package com.demo.ReadWriteLock;

import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * 读写锁：一个实例只有一把锁，现将该锁拆分成读锁和写锁，属于共享锁范畴
 * 试用场景：读多写少的场景，可以大幅度提高效率
 * 问题由来：针对一个共享资源来说，若两个线程同时访问只是进行读数据，那么就不必要进行同步加锁，若两个线程进行读写，才需要加锁同步。
 *
 */
public class Demo01 {
    static ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock();


    static  ReentrantReadWriteLock.ReadLock getReadLock(){
        ReentrantReadWriteLock.ReadLock readLock= readWriteLock.readLock();
        return  readLock;
    }

    static  ReentrantReadWriteLock.WriteLock getWriteLock(){
        ReentrantReadWriteLock.WriteLock writeLock= readWriteLock.writeLock();
        return  writeLock;
    }


}
